<?php
class MunicipalitiesController extends AppController{
	
	var $uses = Array("Municipality","Company","City","User","Group");
	
	public function index(){
		
		$this->set('municipalities',$this->Municipality->find('all'));
		
	}
	
	/**
	 * Kreiraj opshtina/oblast
	 * 
	 * @return void
	 */
	public function create(){		
		
		//var_dump($this->data);
		
		if(isset($this->params['named']['city'])){
			
			$conditions = array("City.id" => $this->params['named']['city']);
			
		}elseif(isset($this->data['Municipality']['city_id'])){
			
			$municipality = $this->Municipality->save($this->data);
			
			if($municipality){
				
				$this->flash("Opshtina kreirana",array('controller'=>'municipalities','action'=>'details','city'=>$this->data['Municipality']['city_id']),2);
					
			}
			
			$conditions = array("City.id" => $this->data['Municipality']['city_id']);
			
			
		}else{
			// ako nema id na gradot
			// redirektiraj kon gradovi
			$this->redirect("/cities");
		}
		
		$city = $this->City->find('first',$conditions);		
		$this->set('city',$city);
		
	}
	
	public function edit(){
		
	}
	
	public function delete(){
		
	}
	
	/**
	 * Detali za oblasta
	 * Lista na kompanii i objekti
	 * @return void
	 */
	public function details(){

		if(!empty($this->params['named']['municipality'])){
			
		}else{
			$this->redirect("/municipalities");
		}
	}
}